我正在尝试从字符串中解析单词并将它们放入数组中。我试过以下方法:@string1="orienteddesign,decomposition,encapsulation,andtesting.Uses"puts@string1.scan(/\s([^\,\.\s]*)/)它似乎可以解决问题,但它有点不稳定(例如,我应该包括更多特殊字符)。在ruby中有更好的方法吗?可选:我有一个CS类(class)描述。我打算把里面的所有单词都提取出来放在一个字符串数组中,从生成的数组中去掉英语中最常见的单词,然后把剩下的单词作为标签,用户可以用来搜索cs类(class)。
选择有意义。但是有人可以向我解释.detect吗?我不明白这些数据。>>[1,2,3,4,5,6,7].detect{|x|x.between?(3,4)}=>3>>[1,2,3,4,5,6,7].detect{|x|x.between?(3,6)}=>3>>[1,2,3,4,5,6,7].detect{|x|x.between?(3,7)}=>3>>[1,2,3,4,5,6,7].detect{|x|x.between?(2,7)}=>2>>[1,2,3,4,5,6,7].detect{|x|x.between?(1,7)}=>1>>[1,2,3,4,5,6,7].detect{|x